package com.yupi.oj.ojMQ.orderMQ;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;

public class OrderMqInitMain {
    public static void main(String[] args) {
        try {
            String EXCHANGE_NAME = orderConstant.EXCHANGE_NAME;
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            HashMap<String, Object> map = new HashMap<>();
            //"x-message-ttl"  指定消息过期时间
            map.put("x-message-ttl",90000);
            Channel channel = connection.createChannel(); //队列1
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT); //这是交换机，通用的

            String queueName = orderConstant.QUEUE_NAME;
            channel.queueDeclare(queueName,true,false,false,map);
            channel.queueBind(queueName, EXCHANGE_NAME, orderConstant.ROUTING_KEY);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
